Hashing an object

Hi,
what does the term "hashing" mean ? What is the conceptual significance of this term ? is it specific to JAVA or is general to OOP/Programming.
Although I know that hashing is used in "collections" interfaces in java.util package, I m just curious to know about the significance of hashing-- as is applicable in general and not specific to the use in collection.
regards

as is
applicable in general and not specific to the use in
collection.It's a very general concept. See any introductory textbook on algoritms and data structures. The general idea is that you map data values from a large domain (like say all Strings) to a much smaller set of values (like say the integers between 0 and N-1). The first step in this mapping process is provided by the hashCode method in the Java class Object.

Similar Messages

  • Hashed Adapter Object

    In designing my code I am trying to avoid multiple if else/switch statements. I have been looking at differing design patterns, and I have come across the Hashed Adapter Object. The key can be used to lookup the correct value object without having to do multiple if else or case statements. I am curious if this approach can have drawbacks if the hashtable gets significantly large. For example, will the instantiation of the hashtable require too much time or memory when the size is greater than a 1000? Is there a better design pattern to use to avoid the if else/switch statements when doing a lookup?

    hello_world wrote:
    In designing my code I am trying to avoid multiple if else/switch statements. I have been looking at differing design patterns, and I have come across the Hashed Adapter Object. The key can be used to lookup the correct value object without having to do multiple if else or case statements. I am curious if this approach can have drawbacks if the hashtable gets significantly large. For example, will the instantiation of the hashtable require too much time or memory when the size is greater than a 1000? Is there a better design pattern to use to avoid the if else/switch statements when doing a lookup?If all you want to do is store values in a hashtable, there's no pattern there, it's just called "using a hashtable".
    If you are talking about putting objects that implement a common interface as values in the hashtable and looking them up based on a key, that's basically a simple form of the Strategy pattern.
    Putting an object in a hashtable merely means putting a reference to an existing object in the table. A handful of bytes for each mapping. 1000 mappings is nothing. If you are wrapping primitives and placing them in the hashtable, that will consume more memory (mitigated in newer versions of the JDK if you use valueOf()) but it's still minuscule compared to the commonly available memory for Java applications. 1000 isn't much even in memory constrained environments. Hashtables are also very fast. Adding lots of elements will not (in general) make access significantly slower.
    Lastly, make sure you use HashMap and not Hashtable.

  • Hashing openoffice objects

    How can I find out if I can put something like an XTextFrame in a hashmap, without erroneous collisions?
    It is not easy to easy if they implement hashcode or equals.
    What would happen? I suppose I am hashing a pointer to an XTextFrame, that would work in most instances no? I know for a fact that they are different, so I don't expect any collisions.
    thanks.

    You can put ANY object in a HashMap, regardless of how it implements the hashCode() method. There may be collisions, that's the nature of a hash map. But you will only have unexpected results if there are two objects A and B where A.equals(B) and A.hashCode() != B.hashCode().
    Such code is unlikely to be written by competent programmers. If it were me, I would assume that Open Office wasn't written by idiots.

  • Client unable to get the javax.activation.DataHandler object from Server

    Hi All,
    I am trying to download the file from the server to the client using Javax.Activation.Data Handler object with IBM web services. But server always returning the Data Handler object is null. I am wondering why it is behaving like this.
    My requirement is add the file to the Data Handler object from the server and read the same from the client. But I am always getting Data Handler object is  null at the client place.
    Please see the client side code and server side code below.
    Server side Code:
    This is the simple web service method, its creating the Data Handler object and adding it to the Hash Map and returning the Hash Map object to the client.
    public Hashtable download()
              DataHandler dh = null;
              HashMap hashMap =new HashMap();
              try{
                   //Sample test files contains data
                   String downLoadFName="C:/ADP/downLoadData.txt";
                   //Creating the DataHandler Object with sample file
                   dh      =      new DataHandler(new FileDataSource(new File(downLoadFName)));
                   //Keeping the DataHandler object in the HashMap.
                   hashMap.put("DATAHANDLER",dh);
                   //keeping the sample test message object in the HashMap
                   hashMap.put("TEST","Keeping the DataHandler and test messages in the hashTable");                         
              }catch(Exception e){
                   logger.error("Error :while sending the data:"+e.getMessage(), e);
              //retrun the HashMap object to the client.
              return hashMap;
    Client Side Code:
    This is the simple client code, and connecting to the server and invoking the web service method
    //This is the client code,Just invoking the webservice method from the Webspehre server.
    public class WebserviceClient {
         static DocumentTransfer controller     =     null;
         public static void main(String args[]){     
                DocumentTransferService service          =     null;
              try{
                   //Creating the service Object
                   service               =     new DocumentTransferServiceLocator();
                   //Getting the Server connection
                    controller          =      (DocumentTransfer)service.getDocumentTransfer(new java.net.URL("http://localhost:9081/eNetsRuntimeEngine/services/DocumentTransfer"));
                    //Calling the download method from the server and it returns HashMap object.
                   HashMap hashMap     = controller.download();
                   //Getting the DataHandler Object from the HashMap
                    DataHandler dh=(DataHandler)hashMap.get("DATAHANDLER");
                   System.out.println("DATAHANDLER: :"+dh);
                   //Getting the String object from the HashMap.
                   String message=(String)hashMap.get("TEST");
                   System.out.println(": :"+message);
               }catch(Exception e){
                    System.out.println("Exception :Not able to get the file :"+e.getMessage());
    Could you please give me some inputs on this?
    Thanks in advance,
    Sreeni.

    Hi Stif,
    Thanks for your response.I did debug from server side,it has printing content of Data Handler properly.
    Also i have debug request and response messages using TCP/IP monitor(RAD environment has this feature).The response from the server is going proplery.
    But the client side Data Handler is coming null.
    Any advice or solution would be greatly appreciated.
    Thanks,
    Sreeni.

  • Strange memory behaviour using the System.Collections.Hashtable in object reference

    Dear all,
    Recently I came across a strange memory behaviour when comparing the system.collections.hashtable versus de scripting.dictionary object and thought to analyse it a bit in depth. First I thought I incorrectly destroyed references to the class and
    child classes but even when properly destroying them (and even implemented a "SafeObject" with deallocate method) I kept seeing strange memory behaviour.
    Hope this will help others when facing strange memory usage BUT I dont have a solution to the problem (yet) suggestions are welcome.
    Setting:
    I have a parent class that stores data in child classes through the use of a dictionary object. I want to store many differenct items in memory and fetching or alteging them must be as efficient as possible using the dictionary ability of retrieving key
    / value pairs. When the child class (which I store in the dictionary as value) contains another dictionary object memory handeling is as expected where all used memory is release upon the objects leaving scope (or destroyed via code). When I use a system.collection.hashtable
    no memory is released at all though apears to have some internal flag that marks it as useable for another system.collection.hashtable object.
    I created a small test snippet of code to test this behaviour with (running excel from the Office Plus 2010 version) The snippet contains a module to instantiate the parent class and child classes that will contain the data. One sub will test the Hash functionality
    and the other sub will test the dictionary functionality.
    Module1
    Option Explicit
    Sub testHash()
    Dim Parent As parent_class
    Dim d_Count As Double
    'Instantiate parent class
    Set Parent = New parent_class
    'Create a child using the hash collection object
    Parent.AddChildHash "TEST_hash"
    Dim d_CycleCount As Double
    d_CycleCount = 50000
    'Add dummy data records to the child container with x amount of data For d_Count = 0 To d_CycleCount
    Parent.ChildContainer("TEST_hash").InsertDataToHash CStr(d_Count), "dummy data"
    Next
    'Killing the parent when it goes out of scope should kill the childs. (Try it out and watch for the termination debug messages)
    'According to documentation and debug messages not really required!
    Set Parent.ChildContainer("TEST_hash") = Nothing
    'According to documentation not really as we are leaving scope but just to be consistent.. kill the parent!
    Set Parent = Nothing
    End Sub
    Sub testDict()
    Dim Parent As parent_class
    Dim d_Count As Double
    'Instantiate parent class
    Set Parent = New parent_class
    'Create a child using the dictionary object
    Parent.AddChildDict "TEST_dict"
    Dim d_CycleCount As Double
    d_CycleCount = 50000
    'Blow up the memory with x amount of records
    Dim s_SheetCycleCount As String
    s_SheetCycleCount = ThisWorkbook.Worksheets("ButtonSheet").Range("K2").Value
    If IsNumeric(s_SheetCycleCount) Then d_CycleCount = CDbl(s_SheetCycleCount)
    'Add dummy data records to the child container
    For d_Count = 0 To d_CycleCount
    Parent.ChildContainer("TEST_dict").InsertDataToDict CStr(d_Count), "dummy data"
    Next
    'Killing the parent when it goes out of scope should kill the childs. (Try it out and watch for the termination debug messages)
    'According to documentation and debug messages not really required!
    Set Parent.ChildContainer("TEST_dict") = Nothing
    'According to documentation not really as we are leaving scope but just to be consistent.. kill the parent!
    Set Parent = Nothing
    End Sub
    parent_class:
    Option Explicit
    Public ChildContainer As Object
    Private Counter As Double
    Private Sub Class_Initialize()
    Debug.Print "Parent initialized"
    Set ChildContainer = CreateObject("Scripting.dictionary")
    End Sub
    Public Sub AddChildHash(ByRef ChildKey As String)
    If Not ChildContainer.Exists(ChildKey) Then
    Dim TmpChild As child_class_hashtable
    Set TmpChild = New child_class_hashtable
    ChildContainer.Add ChildKey, TmpChild
    Counter = Counter + 1
    Set TmpChild = Nothing
    End If
    End Sub
    Public Sub AddChildDict(ByRef ChildKey As String)
    If Not ChildContainer.Exists(ChildKey) Then
    Dim TmpChild As child_class_dict
    Set TmpChild = New child_class_dict
    ChildContainer.Add ChildKey, TmpChild
    Counter = Counter + 1
    Set TmpChild = Nothing
    End If
    End Sub
    Private Sub Class_Terminate()
    Debug.Print "Parent being killed, first kill all childs (if there are any left!) - muahaha"
    Set ChildContainer = Nothing
    Debug.Print "Parent killed"
    End Sub
    child_class_dict
    Option Explicit
    Public MemmoryLeakObject As Object
    Private Sub Class_Initialize()
    Debug.Print "Child using Scripting.Dictionary initialized"
    Set MemmoryLeakObject = CreateObject("Scripting.Dictionary")
    End Sub
    Public Sub InsertDataToDict(ByRef KeyValue As String, ByRef DataValue As String)
    If Not MemmoryLeakObject.Exists(KeyValue) Then MemmoryLeakObject.Add KeyValue, DataValue
    End Sub
    Private Sub Class_Terminate()
    Debug.Print "Child using Scripting.Dictionary terminated"
    Set MemmoryLeakObject = Nothing
    End Sub
    child_class_hash:
    Option Explicit
    Public MemmoryLeakObject As Object
    Private Sub Class_Initialize()
    Debug.Print "Child using System.Collections.Hashtable initialized"
    Set MemmoryLeakObject = CreateObject("System.Collections.Hashtable")
    End Sub
    Public Sub InsertDataToHash(ByRef KeyValue As String, ByRef DataValue As String)
    If Not MemmoryLeakObject.ContainsKey(KeyValue) Then MemmoryLeakObject.Add KeyValue, DataValue
    End Sub
    Private Sub Class_Terminate()
    Debug.Print "Child using System.Collections.Hashtable terminated"
    Set MemmoryLeakObject = Nothing
    End Sub
    Statistics:
    TEST: (Chronologically ordered)
    1.1 Excel starting memory: 25.324 kb approximately
    Max memory usage after hash (500.000 records) 84.352 kb approximately
    Memory released: 0 %
    1.2 max memory usages after 2nd consequtive hash usage 81.616 kb approximately
    "observation:
    - memory is released then reused
    - less max memory consumed"
    1.3 max memory usages after 3rd consequtive hash usage 80.000 kb approximately
    "observation:
    - memory is released then reused
    - less max memory consumed"
    1.4 Running the dictionary procedure after any of the hash runs will start from the already allocated memory
    In this case from 80000 kb to 147000 kb
    Close excel, free up memory and restart excel
    2.1 Excel starting memory: 25.324 kb approximately
    Max memory usage after dict (500.000 records) 90.000 kb approximately
    Memory released: 91,9%
    2.2 Excel starting memory 2nd consequtive dict run: 27.552 kb approximately
    Max memory usage after dict (500.000 records) 90.000 kb approximately
    Memory released: 99,4%
    2.3 Excel starting memory 3rd consequtive dict run: 27.712 kb approximately
    Max memory usage after dict (500.000 records) 90.000 kb approximately
    Memory released:

    Hi Cor,
    Thank you for going through my post and took the time to reply :) Most apreciated. The issue I am facing is that the memory is not reallocated when using mixed object types and is not behaving the same. I not understand that .net versus the older methods
    use memory allocation differently and perhaps using the .net dictionary object (in stead of the scripting.dictionary) may lead to similar behaviour. {Curious to find that out -> put to the to do list of interesting thingies to explore}
    I agree that allocated memory is not a bad thing as the blocks are already assigned to the program and therefore should be reallocated with more performance. However the dictionary object versus hashtable perform almost identical (and sometimes even favor
    the dictionary object)
    The hashtable is clearly the winner when dealing with small sets of data.
    The issue arises when I am using the hash table in conjunction with another type, for example a dictionary, I see that the dictionary object's memory is stacked on top of the claimed memory space of the hashtable. It appears that .net memory allocation and
    reuse is for .net references only. :) (Or so it seems)
    In another example I got with the similar setup, I see that the total used memory is never released or reclaimed and leakage of around 20% allocated memory remains to eventually crash the system with the out of memory message. (This is when another class
    calls the parent class that instantiates the child class but thats not the point of the question at hand)
    This leakage drove me to investigate and create the example of this post in the first place. For the solution with the class -> parent class -> child class memory leak I switched all to dictionaries and no leakage occurs anymore but nevertheless thought
    it may be good to share / ask if anyone else knows more :D (Never to old to learn something new)

  • Creating hash table with more than two columns

    Hello,
    I tried to search around and can't quite find what I'm trying to do. I know I can make a hash table like:
    $Hash = @{"Texas" = "Hot";"Alaska" = "Cold"}
    But I would like to add a third column, so for the sake of an example have the third one say travel by air and the other travel by car. What's the syntax so I can add more columns than two? Also, how can I change the column header names?

    I think you want something more like this:
    New-Object PSObject -property @{
    State="Texas"
    Temp="Hot"
    Travel="Air"
    If I set $hash to equal that:
    $hash = New-Object PSObject -property @{State="Texas";Temp="Hot";Travel="Air"}
    I get this:
    Travel                                  Temp                                    State
    Air                                     Hot                                    
    Texas
    If I have a master variable
    $hashes = @()
    I can set $hash to the new-object of relevant values each pass of a loop:
    $hash = New-Object PSObject -property @{State="Alaska";Temp="Cold";Travel="Car"}
    And add that to $hashes each time:
    $hashes += $hash
    and add to the collection:
    Travel                                  Temp                                    State
    Air                                     Hot                                    
    Texas
    Car                                     Cold                                    Alaska
    As mjolinor suggested, you really need to understand what you want to do.  I suspect you are just unfamiliar with the terms, because what you're describing is an array of values, which is better suited to a PSObject rather than to a hash table.  
    The method for populating a PSObject I describe above is just one variation of one particular method for doing so, there are others that may be more or less suitable for what you want to do.
    I hope this post has helped!
    Thank you, this is what I was looking for. I've never had to use powershell for this type of task before and did know of this process, and only could find hash tables when I poked around. This will make life much easier! 

  • Multidimensional array in jquery class/object

    I'm trying to get into javascript and jquery for a hobby project of mine. Now I've used the last 4 hours trying to find a guide on how to create class objects that can contain the following information
    Identification : id
    Group : group
    Persons : array(firstname : name, lastname : name)
    Anyone know of a tutorial that can show me how to do this?
    I found this page where I can see that an object can contain an array, but it doesn't state whether it is possible to use a multidimensional array.
    And this page just describes the object with normal values.
    Any pointers in the right direction are appreciated.

    There are no classes in JavaScript. It uses a different style of objects and what you found is indeed what you need.
    Well, it might help to think about it as a dynamic, runtime-modifiable object system. An Object is not described by class, but by instructions for its creation.
    Here you have your object. Note that you can use variables everywhere.
    var id = 123;
    var test = {"Identification": id,
    "Group": "users",
    "Persons": [{"firstname":"john", "lastname":"doe"},{"firstname":"jane","lastname":"doe"}]
    This is identical to the following code. (The first one is a lot nicer, though.)
    var id = 123;
    var test = new Object();
    test.Identification = id;
    test["Group"] = "users;
    test.Persons = new Array();
    test.Persons.push({"lastname":"doe","lastname":"john"});
    test.Persons.push({"lastname":"doe","lastname":"jane"});
    As you can see, you can dynamically add new properties to an object. You can use both the dot-syntax (object.property) and the hash syntax (object["property"]) in JavaScript.

  • What is hash code in Java and how it is related to equals method

    Can any body give me the detailed information about hashcode and the relationship between equals method and hash code.

    Objects in Java have hash codes associated with them. An object's hash code is a signed number that identifies the object (for example, an instance of the parent class). An object's hash code may be obtained by using the object's hashCode() method as follows:
    int hashCode = SomeObject.hashCode();
    The method hashCode() is defined in the Object class and is inherited by all Java objects. The following code snippet shows how the hash codes of two objects relate to the corresponding equals() method:
    1. // Compare objects and then compare their hash codes
    2. if (object1.equals(object2)
    3. System.out.println("hash code 1 = " + object1.hashCode() +
    4. ", hashcode 2 = " + object2.hashCode());
    5.
    6. // Compare hash codes and then compare objects
    7. if (object1.hashCode() == object2.hashCode())
    8. {
    9. if (object1.equals(object2))
    10. System.out.println"object1 equals object2");
    11. else
    12. System.out.println"object1 does not equal object2");
    13. }
    In lines 3-4, the value of the two hash codes will always be the same. However, the program may go through line 10 or line 12 in the code. Just because an object's reference equals another object's reference (remember that the equals() method compares object references by default), it does not necessarily mean that the hash codes also match.
    The hashCode() method may be overridden by subclasses. Overriding the hash code will allow you to associate your own hash key with the object.

  • Exchanging objects from mobile to server.

    Hi,
    I'm working in a project that needs to send and receive objects from a mobile client, i know java me does not suport serialization, so, we do not have ObjectOutputStream and ObjectInputStream classes... but, anyone worked in a project with thats requirements? how you pass objects between server and mobile? we are analizing the possibility of make a framework, this one converts a object in the mobile for a xml and the server parse the xml in a new object, we will need to work with aspectj or something like this to intercept the methods and abstract totally de parsing, but this requires time, and we are very close in the project, can someone tell me what to do?
    Thank you
    André Martins

    The HARD WAY:
    The thing you are trying is complicated. First of all, a mechanism to write "any" type of object is very complicated. You have to take
    care of any type of Class. There is a way of doing this but you have to work many months.
    Java offers a mechanism to extract Class information at runtime by using "Class.Class" type. When you serialize an object, you care about internal fields and not
    methods, so you have to extract fields information in triplets : (type, fieldName, value). After you extract all these triplets you define a protocol
    of writing fields into a byte array with DataOutputStream;
    This is the simplest way, but here rises a problem: what if the fields are not primitive values(float, integer, etc..). These
    types are indivisible; but a reference to another object is not an indivisible field. So here comes a recursive way of analyze the
    class: For every indivisible field you have to apply the same algorithm. You apply this until no more reference types are found.
    At the end, the "map" of one Class will look like a tree data structure, where the root is the class type to serialize and the leafs are
    primitive types that are indivisible. Intermediary nodes are references(Class types). By doing so you create a map of the entire Class dependencies.
    Another problem rises here: what if references are in cycle? This means that the previous algorithm works in infinite loop. To avoid this you have
    to create a hash map and add at recursive reference traversal in the hash map objects already mapped. In this case the references between Class types
    creates a graph topology and not a tree topology. By adding this hash of already visited and mapped objects you create a spanning tree over the graph and
    avoid infinite looping.
    After creating the spanning tree, you apply a traversal algorithm(BFS - Breadth First Search) and for every node you write, using the DataOutputStream object,the
    triplets.
    In order to separate the objects into the byte stream, you have to add "offset information" for every Class type you write, in order to read at the other end the correct instances. For a real example of coding this offsets and "pointers" try to implement from scratch the DNS protocol(application layer protocol used to translate a domain name into IP address).
    The EASY WAY
    The easy way is to create a finite number of objects that can be serialized. To do this you have to combine two Design Patterns - Abstract Factory and Memento.
    The Abstract Factory pattern is used to instantiate a family of objects into an uniform way and context. The Memento pattern is used to save a specific state of one object or group of objects. So, you define an Abstract Factory that creates Mementos from objects you want to serialize. Of course the number of objects(or families) is limited, but sufficient to fit your communication needs. On Sender you create mementos that encapsulate the state of objects and send them to Receiver that uses the same factory type to recreate the original object from the memento, but you have to do it by hand: for every class type you have to "recreate" the original configuration by telling the meaning of the received bytes. Also, the memento object must have a low complexity, so you can code it, and not to be a representation of a tree with 10 levels.

  • Assist with my SQL Reporting Script

    I have started writing a HTML SQL reporting script based off of Jeffrey Hicks tutorial
    Here is my entire script:
    ###################START SCRIPT#####################################
    #requires -version 3.0
    #Create a SQL Server report of said SQL environment
    [cmdletbinding()]
    Param(
    [string]$computername=$env:computername,
    [string]$path="$env:temp\sqlrpt.htm"
    #define an empty array to hold all of the HTML fragments
    #the fragments will break apart each HTML section in the final output so that you can out whatever information you like
    $fragments=@()
    #save current location so I can set it back after importing SQL module
    $curr = get-location
    #import the SQL module
    Import-Module SQLPS -DisableNameChecking
    #change the location back
    set-location $curr
    #get uptime
    Write-Verbose "Getting SQL Server uptime"
    $starttime = Invoke-Sqlcmd -Query 'SELECT sqlserver_start_time AS StartTime FROM sys.dm_os_sys_info' -ServerInstance $computername -database master
    $version = Invoke-Sqlcmd "Select @@version AS Version"
    #create an object
    $uptime = New-Object -TypeName PSObject -Property @{
     StartTime = $starttime.Item(0)
     Uptime = (Get-Date)-$starttime.Item(0)
     Version = $version.Item(0).replace("`n","|")
    $tmp = $uptime | ConvertTo-HTML -fragment -AS List
    #replace "|" place holder with <br>"
    $fragments += $tmp.replace("|","<br>")
    #SQL Host Information
    $smo = new-object ('Microsoft.SqlServer.Management.Smo.Server') $computername
    $fragments += "<h3>SQL Host Information Details</h3>"
    $fragments += $smo | select ComputerNamePhysicalNetBios,Name, Processors, ProcessorUsage, PhysicalMemory, PhysicalMemoryUsageInKB, MasterDBPath, BackupDirectory | ConvertTo-HTML -Fragment
    #Get Status of all SQL related Services
    Write-Verbose "Querying services"
    $services = Get-Service -DisplayName *SQL* -ComputerName $computername |
    Select Name,Displayname,Status
    $fragments += "<h3>SQL Services</h3>"
    $fragments += $services | ConvertTo-HTML -Fragment
    #get databases
    #path to databases
    Write-Verbose "Querying datases"
    $dbpath = "SQLServer:\SQL\Localhost\default\databases"
    $fragments += "<h3>Database Utilization</h3>"
    $fragments += dir $dbpath | Select Name,Size,DataSpaceUsage,SpaceAvailable,
    @{Name="PercentFree";Expression={ [math]::Round((($_.SpaceAvailable/1kb)/$_.size)*100,2) }} |
    Sort PercentFree | ConvertTo-HTML -fragment
    #get database backup information
    # Create an SMO connection to the instance
    $smo = new-object ('Microsoft.SqlServer.Management.Smo.Server') $computername
    $dbbackups = $smo.Databases
    $fragments += "<h3>Last Database Backup Information</h3>"
    $fragments += $dbbackups | select Name,LastBackupDate, LastLogBackupDate | ConvertTo-HTML -Fragment
    #Login & Service Account Information#SQL Host Information
    $smo = new-object ('Microsoft.SqlServer.Management.Smo.Server') $computername
    $fragments += "<h3>Login & Service Account Information</h3>"
    $fragments += $smo | select ServiceAccount, Logins | ConvertTo-HTML -Fragment
    #volume usage
    Write-Verbose "Querying system volumes"
    $data = Get-CimInstance win32_volume -filter "drivetype=3" -ComputerName $computername
    $drives = foreach ($item in $data) {
        $prophash = [ordered]@{
        Drive = $item.DriveLetter
        Volume = $item.DeviceID
        Compressed = $item.Compressed
        SizeGB = $item.capacity/1GB -as [int]
        FreeGB = "{0:N4}" -f ($item.Freespace/1GB )
        PercentFree = [math]::Round((($item.Freespace/$item.capacity) * 100),2)
        #create a new object from the property hash
        New-Object PSObject -Property $prophash
    [xml]$html = $drives | ConvertTo-Html -fragment
    #check each row, skipping the TH header row
    for ($i=1;$i -le $html.table.tr.count-1;$i++) {
      $class = $html.CreateAttribute("class")
      #check the value of the last column and assign a class to the row
      if (($html.table.tr[$i].td[-1] -as [int]) -le 25) {                                         
        $class.value = "danger" 
        $html.table.tr[$i].Attributes.Append($class) | Out-Null
      elseif (($html.table.tr[$i].td[-1] -as [int]) -le 35) {                                              
        $class.value = "warn"   
        $html.table.tr[$i].Attributes.Append($class) | Out-Null
    $fragments += "<h3>Volume Utilization</h3>"
    $fragments += $html.innerxml
    #define the HTML style
    Write-Verbose "preparing report"
    $imagefile = "c:\scripts\db.png"
    $ImageBits = [Convert]::ToBase64String((Get-Content $imagefile -Encoding Byte))
    $ImageHTML = "<img src=data:image/png;base64,$($ImageBits) alt='db utilization'/>"
    $head = @"
    <style>
    body { background-color:#FAFAFA;
           font-family:Arial;
           font-size:12pt; }
    td, th { border:1px solid black;
             border-collapse:collapse; }
    th { color:white;
         background-color:black; }
    table, tr, td, th { padding: 2px; margin: 0px }
    tr:nth-child(odd) {background-color: lightgray}
    table { margin-left:50px; }
    img
    float:left;
    margin: 0px 25px;
    .danger {background-color: red}
    .warn {background-color: yellow}
    </style>
    $imagehtml
    <br><br><br>
    <H2>SQL Server Report: $Computername</H2>
    <br>
    #create the HTML document
    ConvertTo-HTML -Head $head -Body $fragments -PostContent "<i>report generated: $(Get-Date)</i>" |
    Out-File -FilePath $path -Encoding ascii
    Write-Verbose "Opening report"
    Invoke-Item $path
    ######################END SCRIPT##################################
    I have 2 questions for help in regards to the above script:
    1)  For the Login and Service Account portion I can't get my output to show up properly.  Here is the snip from the script:
    #Login & Service Account Information#SQL Host Information
    $smo = new-object ('Microsoft.SqlServer.Management.Smo.Server') $computername
    $fragments += "<h3>Login & Service Account Information</h3>"
    $fragments += $smo | select ServiceAccount, Logins | ConvertTo-HTML -Fragment
    Here is how the output shows for this portion:
    ServiceAccount
    Logins
    domain\svcAcct
                 Microsoft.SqlServer.Management.Smo.LoginCollection
    I would like top have the login information show in the above table of the all the different logins.  When I run the script without HTML for that portion and just output to console it shows the login info as I would expect.
    2)  The 2nd question is, how do I add a variable to the bottom of the script to email the report to said email address.  This is probably simple but can't get my head wrapped around this part.
    Thanks all in advance!

    Thanks AnnaWY, that resolved the portion on how to email the report.  I was also able to utilize the following code which does the same thing as well:
    #Send an email with the contents of the report
    $MailBody= Get-Content $path
    $MailSubject= "SQL Server Report"
    $SmtpClient = New-Object system.net.mail.smtpClient
    $SmtpClient.host = "smtp.server.com"
    $MailMessage = New-Object system.net.mail.mailmessage
    $MailMessage.from = "[email protected]"
    $MailMessage.To.add("[email protected]")
    $MailMessage.Subject = $MailSubject
    $MailMessage.IsBodyHtml = 1
    $MailMessage.Body = $MailBody
    $SmtpClient.Send($MailMessage)
    I still have not been able to resolve the portion regarding the login/service account information not showing up in the table correctly.  For the time being I have removed it from the environment report and instead included it as a script of its own
    in our Security Auditing process.

  • Set an indeterminate number of variables

    Hi fellow scriptologists... I thought I was good at this but I'm not as good as I thought I was...
    I need to create a number of variables (Variable1, Variable2 etc) based on the contents of a list of indeterminate length - headings of a document that's likely to change each time it's run. I'd like to assign a name to each variable that reflects its initial value ("Camera", "Shot", "Take", "Slate") although generic names would do, but my impression is that there's no way to ascribe a string to a variable name based on anything done within the script - you simply have to name it or you end up redefining another variable. And if you don't know how many you need, do you need to declare them all up front in order to be able to set them as required?
    There may be a way, but I can't figure out how... any input appreciated.

    Hello
    You might be looking for something like hash table perhaps? Unlike other modern scripting languages, AppleScript has never had built-in hash table. Here's some options.
    Option 1. Use unnamed collection in lieu of named variables. This is straightforward method which should suffice in most cases.
    E.g., use:
    set vars to {1, 2, 3, 4, 5}
    in lieu of:
    set var1 to 1
    set var2 to 2
    set var3 to 3
    set var4 to 4
    set var5 to 5
    Option 2. Implement your own hash table (associative array) if you really want to.
    E.g.,
    set h to assoc()'s new(127)
    h's store({"var1", 1, "var2", 2, "var3", 3, "var4", 4, "var5", 5})
    --return h's ht
    --return h's fetch("var4")
    return h's fetch({"var3", "var5"})
    on assoc()
        script o
            property name : "assoc"
            property version : "0.12"
            property ht : {} -- ht entry is {} or list of {key, value}
            property sz : 0 -- given in new();  prime number for better performance
            property xx : {}
            property cc : {}
            on hash(s)
                    anything s : key coercible to string
                    return integer : hash code
                set cc to (s as string)'s id as list -- OS X 10.5 or later
                set result to 73
                repeat with c in my cc
                    (result * 37 + c) mod 1048573 as integer
                end repeat
                result mod sz + 1 as integer
            end hash
            on fetch(argv)
                    anything or list argv : key or list of keys (key can be anything coercible to string)
                    return anything or list : value or list of values associated with given key(s)
                        (returns missing value for non-existent key)
                if argv's class = list then
                    set xx to {}
                    repeat with a in argv
                        set my xx's end to fetch(a's contents)
                    end repeat
                    return my xx's contents
                else
                    repeat with h in my ht's item hash(argv) -- linear search in collision
                        if h's item 1 is argv then return h's item 2
                    end repeat
                    return missing value
                end if
            end fetch
            on store(argv)
                    list argv : {key, value} pair or {key1, value1, key2, value2, ...} pairs
                    return list : for given pair {k, v},
                            {k, v} if k does not exist in table; or
                            {{k, v}, {k, v1}} if k exists in table, where v1 is old value for k
                local argc
                set argc to count argv
                if argc > 2 and argc mod 2 = 0 then
                    set xx to {}
                    repeat with i from 1 to argc by 2
                        set my xx's end to store(argv's items i thru (i + 1))
                    end repeat
                    return my xx's contents
                else if argc = 2 then
                    -- separate chaining
                    local p, v1
                    set {k, v} to argv
                    set p to hash(k)
                    repeat with h in my ht's item p -- linear search in collision
                        if h's item 1 = k then
                            set v1 to h's item 2
                            set h's item 2 to v
                            return {{k, v}, {k, v1}} -- {new entry, old entry}
                        end if
                    end repeat
                    set end of my ht's item p to {k, v}
                else
                    error my name & "::store(): odd number of arguments." number 8001
                end if
            end store
            on scratch(argv)
                    anything or list argv : key or list of keys to delete
                    return anything or list : value or list of values associated with deleted key(s)
                        (returns missing value for non-existent key)
                if argv's class = list then
                    set xx to {}
                    repeat with a in argv
                        set my xx's end to scratch(a's contents)
                    end repeat
                    return my xx's contents
                else
                    -- delete key and return key's value if any
                    local p, v, h
                    set p to hash(argv)
                    repeat with i from 1 to count my ht's item p -- linear search in collision
                        set h to my ht's item p's item i
                        if h's item 1 = argv then
                            set v to h's item 2
                            set my ht's item p's item i to false
                            set my ht's item p to my ht's item p's lists
                            return v -- key's value
                        end if
                    end repeat
                    return missing value
                end if
            end scratch
            on keys()
                    return list : list of stored keys (in internal storage order)
                set xx to {}
                repeat with p in my ht
                    repeat with h in p
                        set end of my xx to h's item 1
                    end repeat
                end repeat
                return my xx's contents
            end keys
            on values()
                    return list : list of stored values (in internal storage order)
                set xx to {}
                repeat with p in my ht
                    repeat with h in p
                        set end of my xx to h's item 2
                    end repeat
                end repeat
                return my xx's contents
            end values
            on new(m)
                    integer m : size of hash table to be created (prime number for better performance)
                    return script : initialized hash table object
                if m's class is integer and m > 0 then
                    set sz to m
                    repeat sz times
                        set end of my ht to {}
                    end repeat
                    return o
                else
                    error my name & "::new(): invalid size." number 8000
                end if
            end new
        end script
    end assoc
    Regards,
    H

  • StartupFailureisFatal Property question

    What is name of the registeredclass that we need to specify for the
    startupFailureisFatal property. I have set it to the name of my virtual
    startup class, the name of my startup class, left it alone as
    registeredclass but I don't get the weblogic 4.5 server to shutdown when I
    throw an exception from the startup class. I would appreciate it if someone
    could give me an example of its use. Thanks.
    My weblogic.property file
    weblogic.system.startupClass.mezziaStartup=com.mezzia.planner.admin.MezziaSt
    artup
    weblogic.system.startupArgs.mezziaStartup=serverType=development,\
    serverOwner=me
    I have tried each of the following three settings but none of them cause the
    server to shutdown.
    weblogic.system.startupFailureisFatal.mezziaStartup=true
    weblogic.system.startupFailureisFatal.registeredclass=true
    weblogic.system.startupFailureisFatal.MezziaStartup=true
    I get the following error but the server doesn't shutdown.
    Wed Sep 06 16:37:37 EST 2000:<E> <WebLogicServer> Failed to invoke startup
    class mezziaStartup=com.mezzia.planner.admin.MezziaStartup
    I know it is probably something really simple but I can't figure out what I
    am doing wrong. Thanks Again.
    IRfan
    ---- BEA Documentation for Weblogic 4.5 ----
    You can use the following property to require that specific startup classes
    are correctly loaded before the server will start:
    weblogic.system.startupFailureisFatal.registeredclass=boolean
    The default is false, which will not affect the startup of WebLogic Server.
    If set to true, the server will not start if the class or classes registered
    to the indicated name throw an exception.

    If an expression evaluates to multiple objects, then the Powershell pipeline will automatically create and return an array of those objects.
    If the expression evaluates to a single object (sometimes referred to as being
    scalar) then the pipeline will return one object of that type.
    This can cause problems if the expression is normally expected to return multiple objects, and you write your script to always expect an array to be returned.  To mitigate that, in V3 they added a feature that will synthesize a Count property for the
    object with a value of 1.  But this can only work as long as the object doesn't already have Count property.  If the object already has a Count property, then any reference to .count will return the value of the native property.
    You see the same kind of situation with hash tables.  Hash table objects in Powershell have synthetic .keys and .values properties that return arrays of the hash table keys and values, respectively.  But Powershell syntax also allows you to reference
    hash table keys using the same dot notation used for returning properties.  This produces a conflict if the hash table actually has keys that are named 'keys' or 'values'.  If it does then the actual hash table entry having those key names is returned,
    not they key or value collection.  
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How to simplify complex PowerShell if statemant?

    Good morning,
    please any idea how to simplify following complex PowerShell if statemant?
    if ($child1 |
    Where-Object {$_.operatingsystem -notlike "Windows RT*"} |
    Where-Object {$_.operatingsystem -notlike "Microsoft Office Suite and Other Software"} |
    Where-Object {$_.operatingsystem -notlike "Antimalware Software"} |
    Where-Object {$_.operatingsystem -notlike "*for Mac*"} |
    Where-Object {$_.operatingsystem -notlike "Office Software"} |
    Where-Object {$_.operatingsystem -notlike "Software"} |
    Where-Object {$_.operatingsystem -notlike "Affected Software"} |
    Where-Object {$_.operatingsystem -notlike "File information"} |
    Where-Object {$_.operatingsystem -notlike "SHA1/SHA2 hashes"} |
    Where-Object {$_.operatingsystem -notlike "Known issues"} |
    Where-Object {$_.operatingsystem -notlike "Operating System"} |
    Where-Object {$_.operatingsystem -notlike "*Server*"} |
    Where-Object {$_.operatingsystem -notlike "*Vista x64*" } |
    Where-Object {$_.operatingsystem -notlike "*XP Professional x64*" } |
    Where-Object {$_.operatingsystem -notlike "Microsoft Office Software" }
    {$Parent += $Child1 }
    Thank you :)

    Here:
    $child1 |
    Where-Object{$_.operatingsystem -notlike "Windows RT*"} |
    Where-Object{$_.operatingsystem -notlike "Microsoft Office Suite and Other Software"} |
    Where-Object {$_.operatingsystem -notlike "Antimalware Software"} |
    Where-Object {$_.operatingsystem -notlike "*for Mac*"} |
    Where-Object {$_.operatingsystem -notlike "Office Software"} |
    Where-Object {$_.operatingsystem -notlike "Software"} |
    Where-Object {$_.operatingsystem -notlike "Affected Software"} |
    Where-Object {$_.operatingsystem -notlike "File information"} |
    Where-Object {$_.operatingsystem -notlike "SHA1/SHA2 hashes"} |
    Where-Object {$_.operatingsystem -notlike "Known issues"} |
    Where-Object {$_.operatingsystem -notlike "Operating System"} |
    Where-Object {$_.operatingsystem -notlike "*Server*"} |
    Where-Object {$_.operatingsystem -notlike "*Vista x64*" } |
    Where-Object {$_.operatingsystem -notlike "*XP Professional x64*" } |
    Where-Object {$_.operatingsystem -notlike "Microsoft Office Software" }
    It still won't work because it is just a bunch of mismatched nonsense.  Most lines are meaningless and many will not work as expected.
    ¯\_(ツ)_/¯
    Thank you for your opinion, this is PS not bunch of mismatched nonsense and it is working, just want to simplify it ;)

  • ESSO - LM: Administrative overrides

    Hi,
    I'm deploying eSSO - LM and can't get the administrative overrides to get synchronized from AD. The application templates do get downloaded, but the overrides don't. A trace of the LM Agent shows that it reads a SyncState, then some mysterious hash-named object from the user, then fails to create something because it already exists, a while later it fails to read several objects, and finally it again gives an "object already exists" error. Any ideas? The overrides are in the SSOConfig container, and they are never mentioned in the logs.
    Thanks,
    Juan
    2008-10-30T13:25:31.832Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/RootDSE, 1) user [email protected]" try 1 succeeded               
    2008-10-30T13:25:31.870Z     1868     3040     IADsNameTranslate::Get(ADS_NAME_TYPE_1779) returned "CN=Juan Heguiabehere,OU=Usuarios Consultores, OU=CompanyX,DC=CompanyX,DC=com,DC=ar"               
    2008-10-30T13:25:31.871Z     1868     3040     IADsNameTranslate::Get(ADS_NAME_TYPE_NT4) returned "CompanyX\heguiabj"               
    2008-10-30T13:25:31.873Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:31.880Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:31.994Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.021Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SyncState,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.044Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=DF7DB351-24F7-410B-B205-3C0B639479BF,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.285Z     1868     3040     IDirectoryObject::CreateDSObject failed with 0x80071392               
    2008-10-30T13:25:32.292Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/OU=SSOConfig,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.340Z     1868     3040     AD Bind
    ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=66ea1863-06f8-49dc-917a-82406bbb8063,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 failed 0x80072030               
    2008-10-30T13:25:32.347Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=c26151f3-6a35-4ed2-8da8-4e5921ea04b3,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 failed 0x80072030               
    2008-10-30T13:25:32.355Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=ecb3c31d-ea12-449e-9cfd-b5f382497ce1,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 failed 0x80072030               
    2008-10-30T13:25:32.362Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SSOProvisioning,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.370Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SSOProvisioning,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.382Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SSOProvisioning,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.391Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SSOProvisioning,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.400Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SSOProvisioning,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.410Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SSOProvisioning,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.418Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SSOProvisioning,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.428Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=SSOProvisioning,CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.437Z     1868     3040     AD Bind ADsOpenObject(LDAP://clonad.CompanyX.com.ar:389/CN=Juan Heguiabehere,CN=Juan Heguiabehere,OU=Usuarios Consultores,OU=CompanyX,DC=CompanyX,DC=com,DC=ar, 1) user "[email protected]" try 1 succeeded               
    2008-10-30T13:25:32.577Z     1868     3040     IDirectoryObject::CreateDSObject failed with 0x80071392               
    2008-10-30T13:25:32.585Z     1868     3040     Unloaded plugin: C:\Archivos de programa\Passlogix\v-GO SSO\Plugin\SyncMgr\ADExt\adsync.dll               
    2008-10-30T13:25:33.095Z     1868     3040     Main program loop has finished but some messages were left in the queue.               
    2008-10-30T13:25:33.097Z     1868     3040     Unloaded plugin: C:\Archivos de programa\Passlogix\v-GO SSO\Plugin\SyncMgr\syncmgr.dll               
    2008-10-30T13:25:33.097Z     1868     3040     Unloaded plugin: C:\Archivos de programa\Passlogix\v-GO SSO\Plugin\StorageMgr\InMemShr.dll               
    2008-10-30T13:25:33.097Z     1868     3040     Unloaded plugin: C:\Archivos de programa\Passlogix\v-GO SSO\Plugin\StorageMgr\TextStorage.dll               
    2008-10-30T13:25:33.097Z     1868     3040     Unloaded plugin: C:\Archivos de programa\Passlogix\v-GO SSO\resource.dll               
    2008-10-30T13:25:33.098Z     1868     3040     ExitProcess: 0 (0x00000000)

    two options...
    1 - go to global agent settings ->live->enduser exeperience->response
    Select Display "Add another logon" checkbox
    This will enable a checkbox for when the user 1st enrolls the u/p to fill in a 2nd or 3rd credential
    OR
    2 go to logon manager (the wallet or whatever you call it ) copy the existing credential then change the 2nd credential to what you want.
    when you go to that site you will get a chooser on which one to use
    tomatolord

  • MessageDigest.update

    Hello,
    I'm currently writing an iPhone app which connects and authenticates with a server written in Java. Due to security, I want to send the user data encrypted.
    On the server I use:
    byte[] bSalt = base64ToByte(salt);
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    digest.reset();
    digest.update(bSalt);
    byte[] bToHash = digest.digest(toHash.getBytes("UTF-8"));
    for (int i = 0; i < 3; i++) {
    System.out.println(byteToBase64(bToHash));
    digest.reset();
    digest.update(bSalt); // More secure?
    bToHash = digest.digest(bToHash);
    By now, I managed to hash in Objective C, too, but the salt is the problem. For getting the same hashing results in ObjC, I need to know what MessageDigest.update does. Does it simply compute an OR with the current digest and the salt or what does it do? Thanks for your help.
    Greetings
    Naznaz

    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    digest.reset();The reset() is unnecessary here. You've just created the MessageDigest object. Resetting it won't change anything - there is nothing to change yet.
    digest.update(bSalt);
    byte[] bToHash = digest.digest(toHash.getBytes("UTF-8"));
    for (int i = 0; i < 3; i++) {There is little to gain from repeating the digesting algorithm three times.
    System.out.println(byteToBase64(bToHash));
    digest.reset();Almost certainly wrong. You are throwing away all prior state here, including the salt.
    digest.update(bSalt); // More secure?More secure than what? I suspect you can omit this too.
    bToHash = digest.digest(bToHash);That should almost certainly be update(), not digest(). digest() is the last thing you call, when you get to the last piece of input.
    I need to know what MessageDigest.update does.It's algorithm-dependent, obviously. In this case you are using SHA-256 so you would need to look up that algorithm. It's lengthy!
    Does it simply compute an OR with the current digest and the saltDefinitely not. It applies the specified digest algorithm to its current state and the next piece of input you provide. This code should mirror the code you say you already have working in Objective-C.
    But none of this is encryption. It is message-digesting. The result cannot be decrypted.

Maybe you are looking for